﻿/**
* CRL
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Linq.Expressions;
using System.Collections.Concurrent;

namespace CRL.Data.Attribute
{
    /// <summary>
    /// 表
    /// </summary>
    [AttributeUsage(AttributeTargets.Class)]
    public class TableAttribute : System.Attribute
    {
        string tableName;
        /// <summary>
        /// 表名
        /// MongoDB不支持字段别名
        /// </summary>
        public string TableName
        {
            get
            {
                return tableName;
            }
            set
            {
                tableName = value;
            }
        }

        /// <summary>
        /// 备注
        /// </summary>
        public string Remark
        {
            get;
            set;
        }
        /// <summary>
        /// 默认排序 如Id Desc
        /// </summary>
        public string DefaultSort
        {
            get;
            set;
        }
        /// <summary>
        /// 启用名称混淆
        /// </summary>
        public bool EnableObfuscate { get; set; }
    }

    public class TableInnerAttribute : TableAttribute
    {
        public override string ToString()
        {
            return TableName;
        }

        /// <summary>
        /// 主键
        /// </summary>
        public FieldInnerAttribute PrimaryKey
        {
            get;
            set;
        }
        public FieldInnerAttribute GetPrimaryKey()
        {
            return PrimaryKey;
        }
        /// <summary>
        /// 对象类型
        /// </summary>
        public Type Type { get; set; }

        /// <summary>
        /// 所有字段
        /// </summary>
        public List<FieldInnerAttribute> Fields
        {
            get;
            internal set;
        } = new List<FieldInnerAttribute>();
        /// <summary>
        /// 只存基本数据库字段
        /// </summary>
        public IgnoreCaseDictionary<FieldInnerAttribute> FieldsDic = new IgnoreCaseDictionary<FieldInnerAttribute>();

        /// <summary>
        /// 单字段索引 memberName,script
        /// </summary>
        internal ConcurrentDictionary<string, FieldIndexType> Index = new ConcurrentDictionary<string, FieldIndexType>();
        /// <summary>
        /// 联合索引
        /// </summary>
        internal ConcurrentDictionary<string, UnionIndexItem> UnionIndex = new ConcurrentDictionary<string, UnionIndexItem>();
    }
}
